<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品信息新增</title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>

</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>商品信息新增</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="compList.jsp">采购目录管理</a></li>
            <li class="active"><a href="compEdit.jsp">商品目录管理</a></li>
             <li class="active"><a href="compEdit.jsp">商品查看</a></li>
              <li class="active"><a href="compEdit.jsp">商品信息新增</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-header"></div>
            <!-- form start -->
            <form role="form" class="form-horizontal" action="compList.jsp" method="post">
                <div class="box-body">
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">商品编码：</label>
                        <div class="col-sm-4 text-left">
                            <input class=" form-control" placeholder="商品编码" id="goodsCode" name="goodsCode" type="text">
                        </div>
                        <label class="col-sm-2 text-right">所属项目：</label>
                        <div class="col-sm-4 text-left">
                            <select class=" form-control" name="projId" id="projId">
                            </select>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药品：</label>
                        <div class="col-sm-3 text-left">
                            <input type="hidden" name="drugId" id="drugId" value="">
                             <input class=" form-control" readonly="readonly" placeholder="药品" id="drugName" name="drugName" type="text">
                        </div>
                        <div class="col-sm-1 text-left">
                            <a href="javascript:void(0)" onclick="selectDrug();" class="btn btn-default btn-sm" >选择</a>
                        </div>
                        <label class="col-sm-2 text-right">商品分类：</label>
                        <div class="col-sm-4 text-left">
                            <select class=" form-control" name="drugCat" id="drugCat">
                            </select>
                        </div>
                   </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">采购限价：</label>
                        <div class="col-sm-4 text-left">
                            <input class=" form-control" placeholder="采购限价" id="proPriceLimit" name="proPriceLimit"  type="text">
                        </div>
                        <label class="col-sm-2 text-right">最高零售限价：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" placeholder="最高零售限价" id="retailPriceLimit" name="retailPriceLimit" type="text">
                        </div>
                    </div>
                 <div class="box-footer text-center">
                    <button type="button" onclick="save();" class="btn btn-success btn-sm">保&nbsp;存</button>
                    <button type="button" onclick="back();" class="btn btn-danger btn-sm">返&nbsp;回</button>
                </div>
              </div>
            </form>
        </div>
        
        
        
        
        
        
                <div class="modal fade" id="selectDrug" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择药品</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                        <div class=" box box-success">
            <div class="box-body">
            <div class="form-inline">
                    <div class="form-group form-group-xs">
                         药品编码： 
                        <input class="form-control" type="text" id="drugcode" placeholder="药品编码" />
                    </div>
                    <div class="form-group form-group-xs">
                         通用名： 
                        <input class="form-control" type="text" id="drugname" placeholder="通用名" />
                    </div>
                    
                    <button type="button" class="btn btn-success btn-sm">查询</button>
                </div>
            </div>
        </div>
                        
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist"></table>
        <div id="gridpage col-sm-1"></div>
                            </div>
                        
                        
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="gridOk();" class="btn btn-primary btn-sm">选择</button>
                        <button type="button" onclick="cleandata();" class="btn btn-danger btn-sm" data-dismiss="modal">清空</button>
                    </div>
                </div>
            </div>
        </div>
  
        
        
        
        
        
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
	<script type="text/javascript">
	 $(document).ready(function (){
		 $("#drugCat").HNSelect({
		        url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '115' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
		    });
		 
		 $("#projId").HNSelect({
		        url: "${pageContext.request.contextPath}/selectController/getProject.html", data: { ID: '115' },  defaultText: "<option value=''>请选择</option>",
		    });
	 });
	 function save(){
   	  $.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
             if (e) {
            	 var goodsCode = $.trim($("#goodsCode").val());
            	 if (goodsCode == ""){
            		 $.HN.message.alert("商品编码不能为空！", "消息", "error");
            		 return;
            	 }
            	 var projId = $.trim($("#projId").val());
            	 if (projId == ""){
            		 $.HN.message.alert("请选择所属项目！", "消息", "error");
            		 return;
            	 }
            	 
            	 var drugId = $.trim($("#drugId").val());
            	 if (drugId == ""){
            		 $.HN.message.alert("请选择药品！", "消息", "error");
            		 return;
            	 }
            	 var drugCat = $.trim($("#drugCat").val());
            	 if (drugCat == ""){
            		 $.HN.message.alert("请选择商品分类！", "消息", "error");
            		 return;
            	 }
            	 var proPriceLimit = $.trim($("#proPriceLimit").val());
            	 if (proPriceLimit == ""){
            		 $.HN.message.alert("采购限价不能为空！", "消息", "error");
            		 return;
            	 }
            	 var retailPriceLimit = $.trim($("#retailPriceLimit").val());
            	 if (retailPriceLimit == ""){
            		 $.HN.message.alert("最高零售限价不能为空！", "消息", "error");
            		 return;
            	 }
            	 
            	 $.post("${pageContext.request.contextPath}/baseGoods/addData.html", {
            		 goodsCode : goodsCode, 
            		 projId : projId,
            		 drugId:drugId,
            		 drugCat:drugCat,
            		 proPriceLimit:proPriceLimit,
            		 retailPriceLimit:retailPriceLimit
            		}, function(result) {
            			if (result.success) {
            				$.HN.message.alert("操作成功！", "消息", "success");
            				window.location.href="${ctx}/baseGoods/toList.html";
            			} else {
            				$.HN.message.alert("操作失败！", "消息", "error");
            			}
            		}, "json")
                 
             }
         });
   	
   }
   function back(){
   	window.location.href="${ctx}/baseGoods/toList.html";
   }
   
   $("#gridlist").jqGrid({
       url: "${pageContext.request.contextPath}/stdDrug/getData.html",
       mtype: "POST",
       datatype: "json",
       autowidth: true,
       height: 255,
       shrinkToFit: false,
       colNames: ['id','药品编码',  '通用名', '剂型', '规格', '转换系数', '单位', '生产企业'],
       colModel: [
					{ name: 'drugId', width: 120 ,hidden:true,key:true, align:"center",sortable: false},
					{ name: 'drugCode', width: 85 , align:"center",sortable: false},
					{ name: 'drugName', width: 80 , align:"center" ,sortable: false},
					{ name: 'formName', width: 70 , align:"center" ,sortable: false},
					{ name: 'specName', width: 70 , align:"center" ,sortable: false},
					{ name: 'factor', width: 60 , align:"center" ,sortable: false},
					{ name: 'unit', width: 40 , align:"center" ,sortable: false},
					{ name: 'prodPompName', width: 170 , align:"center",sortable: false }
       ],
       rowNum: 10,
       rowList: [10, 20, 30],
       rownumbers: false,
       pager: "#gridpage",
       //multiselect: true, 
       viewrecords: true,
       caption: "药品选择",
       jsonReader: {
           repeatitems: false,
           id: "ids"
       }
   });
   $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
   $(window).trigger("resize");
   function selectDrug() {
	   $("#drugcode").val("");
	   $("#drugname").val("");
	   gridSerch();
		$('#selectDrug').modal({
			keyboard : true
		});
	}
   function gridSerch() {
	   	var compCode = $("#compCode").val();
	   	var compName = $("#compName").val();
			$("#gridlist1").jqGrid('setGridParam',{  
		        datatype:'json',
		        postData:{"compCode":compCode,
		        		"compName":compName}
		    }).trigger("reloadGrid"); //重新载入  
		}
	   function gridOk(){
		   var drugId = $("#gridlist").jqGrid('getGridParam', 'selrow');
	       if (drugId == null) {
	    	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
	           return;
	       }
	       var rowdata = $("#gridlist").jqGrid('getRowData', drugId);
	       $("#drugId").val(drugId);
	       $("#drugName").val(rowdata.drugName);
	       $("#selectDrug").modal("hide");

	   }
	   function cleandata(){
		   $("#drugId").val("");
	       $("#drugName").val("");
	       $("#selectDrug").modal("hide");
	   }
	</script>
</body>
</html>